<?php

namespace App\Admin\Controllers;

use App\Admin\Actions\AuditWithdrawl;
use App\Admin\Repositories\TongUserWithdrawal;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class TongUserWithdrawalController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new TongUserWithdrawal(['userInfo']), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->model()->orderBy('id', 'desc');
            $grid->column('userInfo.nickname','用户名');
            $grid->column('money','提现金额')->display(function($value){
                return $value.'元';
            });
            $grid->column('real_money','到账金额')->display(function($value){
                return $value.'元';
            });
            $grid->column('status','提现状态')->view('admin.withdrawal.fields.status');
            $grid->column('bank_json_data','银行卡')->display(function($value){
                return json_decode($value,true);
            })->view('admin.withdrawal.fields.bank');
            $grid->column('created_at','申请时间');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->panel();
                $filter->equal('id')->placeholder('请输入提现数据id')->width(3);
                $filter->equal('status','状态')->select([1=>'待审核',2=>'审核通过',3=>'审核拒绝'])->placeholder('请选择审核状态')->width(3);
            });

            $grid->actions(function (Grid\Displayers\Actions $actions){
                $actions->disableDelete();
                $actions->disableEdit();
                $actions->disableQuickEdit();
                $actions->disableView();
                if($this->status==1){
                    $actions->append(AuditWithdrawl::make());
                }

            });
            $grid->disableRowSelector();
            // 禁用添加按钮
            $grid->disableCreateButton();
            //启用导出功能
            $grid->export();

        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new TongUserWithdrawal(), function (Show $show) {
            $show->field('id');
            $show->field('u_id');
            $show->field('money');
            $show->field('status');
            $show->field('bank_json_data');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new TongUserWithdrawal(), function (Form $form) {
            $form->display('id');
            $form->text('u_id');
            $form->text('money');
            $form->text('status');
            $form->text('bank_json_data');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
